Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 9f5067e1930dea377e598315df2bd40b9c30cfeb


Parents : f9ab8ba
Author : Jason <schlesinger@plbl.net>
Date : 2026-05-02T23:47:06+09:00

Fixed glaring bug in files.mu

Changes

1 files changed, 33 insertions(+), 36 deletions(-)

M files.mu +33 -36

Diff

diff --git a/files.mu b/files.mu
index fb5b476..13c9b25 100755
--- a/files.mu
+++ b/files.mu
@@ -3,9 +3,10 @@
# Import required modules
import core
import os
+from pathlib import Path
-# Must be where files are accessible. Typically .nomadnetwork/storage/files
-root = '/root/.nomadnetwork/storage/files'
+# Must be where files are accessible. Typically ~/.nomadnetwork/storage/files
+root = Path.home() / '.nomadnetwork/storage/files'
# Sub folder(s) within root directory, leave blank to disable. Example would be: /photos. Do not leave a trailing slash.
root_sub_folder = ''
@@ -16,41 +17,33 @@ file_mu = 'files.mu'
# Allow only logged in users to browse and download
users_only = False
-
#####################################################
-def up():
- request_split = dir_request.split('/')
- new_path = ''
- for loc in request_split[:-2]:
- new_path = new_path + loc + '/'
- if new_path == '':
- button = ''
- return button
- elif new_path != '':
- button = '`!`[<UP>`:/page/' + file_mu + '`path=' + new_path + ']`! |'
- return button
-
-# Must be browsing locally, create fake link_id
-if 'link_id' not in os.environ:
- os.environ['link_id'] = 'local_test'
+root /= root_sub_folder
+def get_link(dir_request:Path,up=False) -> str:
+ button = ''
+ if up and root == dir_request.parent:
+ button = f'`!`[<UP>`:/page/{file_mu}`path=!home!]`! |'
+ elif up and root in dir_request.parents:
+ button = f'`!`[<UP>`:/page/{file_mu}`path={dir_request.relative_to(root)}]`! |'
+ elif not up:
+ button = f'`!`[<{dir_request.name}>`:/page/{file_mu}`path={dir_request.relative_to(root)}`]`!'
+ return button
-# Check if current link_id is loged in as a user.
-current_session = core.get_current_session(os.environ['link_id'])
+# Check if current link_id is logged in as a user. Use 'local_test' if browsing locally
+current_session = core.get_current_session(os.environ.get('link_id','local_test'))
# Display the header, i.e. title, menu, etc.
core.header(current_session)
-if 'var_path' in os.environ:
-## try:
- if os.environ['var_path'] == '!home!':
- dir_request = '/'
- if os.environ['var_path'] != '!home!':
- dir_request = os.environ['var_path']
-elif 'var_path' not in os.environ:
- dir_request = '/'
+dir_request = root
+if os.environ.get('var_path','!home!') != '!home!':
+ dir_request = (root / os.environ['var_path']).resolve()
+ # Check to see if dir_request is invalid
+ if not dir_request.is_dir() or root not in dir_request.parents:
+ dir_request = root
-header = '''`!`[Index`:/page/''' + file_mu + '''`path=!home!]`! | ''' + up() + ''' Current: ''' + dir_request + '''
+header = f'''`!`[Index`:/page/{file_mu}`path=!home!]`! | {get_link(dir_request.parent,up=True)} Current: {dir_request.relative_to(root)}/
-
'''
@@ -58,16 +51,20 @@ print(header)
if not users_only or current_session:
try:
- for item in os.listdir(root + dir_request):
- if '.' not in item:
- print('`!`[<' + item + '>`:/page/' + file_mu + '`path=' + dir_request + item + '/]`!')
- elif '.' in item:
- file_size = round((os.path.getsize(root + dir_request + item) / 1024) / 1024, 3)
- print('`[' + item + '`:/file' + root_sub_folder + dir_request + item + ']' + ' - ' + str(file_size) + ' MB')
+ for item in dir_request.iterdir():
+ if item.is_dir():
+ print(get_link(item))
+ elif item.is_file():
+ file_size = round((item.stat().st_size / 1024) / 1024, 3)
+ print(f'`[{item.name}`:/file/{item.relative_to(root)}`] - {file_size} MB')
print()
except Exception as e:
- print(e)
+ # Don't give tracebacks to unauthenticated users
+ if current_session:
+ print(e)
+ else:
+ print("Unknown Error Occurred")
elif users_only and not current_session:
print('Login to browse files.')


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────